package org.wevil.controller.news;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wevil.params.page.NewsPP;
import org.wevil.service.NewsService;
import org.wevil.util.JwtUtil;
import org.wevil.util.page.PageResult;
import org.wevil.vo.Result;
import org.wevil.vo.list.NewsListVo;

import javax.annotation.Resource;

/** 新闻管理 */
@RestController
@RequestMapping("news")
public class NewsController {

    @Resource
    NewsService newsService;

    /** 列表 */
    @PostMapping("/list")
    public Result<PageResult<NewsListVo>> list(
            @RequestHeader("token") String token,
            @RequestBody @Validated NewsPP param
    ){
        Integer userId = JwtUtil.getUserId(token);
        PageResult<NewsListVo> page = newsService.page(param, userId, true);
        return Result.success(page);
    }
}
